﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using EventAggregationQuickStart;
using Microsoft.Practices.Composite.Events;

namespace EventAggregationQuickstart
{
    internal class ShellPresenter
    {
        Shell view;
        ITaskService tasks;
        IEventAggregator eventAggregator;

        public ShellPresenter(Shell view, ITaskService tasks, IEventAggregator eventAggregator)
        {
            this.view = view;
            this.tasks = tasks;
            this.eventAggregator = eventAggregator;

            // Subscribe to the Button1Event
            Button1Event customEvent = eventAggregator.GetEvent<Button1Event>();
            customEvent.Subscribe(Button1EventEventHandler, false);
        }
        
        // Event Handler for the event published somewhere else in the system
        private void Button1EventEventHandler(EventArgs data)
        {
            System.Windows.Forms.MessageBox.Show("Shell received event notification for Button1");
        }


        public void StartMainView()
        {
            // Show the start view
            tasks.Execute("FirstView");
        }

        public void StartServices()
        {
            // Start the service
            IServiceThatPublishesEvents svc = 
                ApplicationRoot.Container.Resolve<IServiceThatPublishesEvents>();
        }

    }

}
